// 刚体

#ifndef ALICE_PHYSICS_RIGID_BODY_H_
#define ALICE_PHYSICS_RIGID_BODY_H_

#include "vector2d.h"

namespace alice {

constexpr double kMass = 1.0f;
constexpr double kGravity = 9.8f;

constexpr int kForward = 1;
constexpr int kBackward = -1;
constexpr int kUpward = -1;
constexpr int kDownward = 1;

class RigidBody {
  public:
    RigidBody() {
      mass_ = kMass;
      gravity_ = kGravity;
    }

    void SetMass(double mass) { mass_ = mass; }
    void SetGravity(double gravity) { gravity_ = gravity; }

    void ApplyForce(Vector2D force) { force_ = force; }
    void ApplyForceX(double force_x) { force_.X = force_x; }
    void ApplyForceY(double force_y) { force_.Y = force_y; }
    void UnsetForce() { force_ = Vector2D(0, 0); }

    void ApplyFriction(double friction) { friction_ = friction; }
    void UnsetFriction() { friction_ = Vector2D(0, 0); }

    Vector2D GetForce() { return force_; }

    Vector2D Position() { return position_; }

    void Update(double delta_time) {
      accelaration_.X = (force_.X + friction_.X) / mass_;
      accelaration_.Y = (gravity_ + force_.Y) / mass_;
      velocity_ = accelaration_ * delta_time;
      position_ = velocity_ * delta_time;
    }

  private:
    double mass_;
    double gravity_;
    Vector2D force_;
    Vector2D friction_;
    Vector2D position_;
    Vector2D velocity_;
    Vector2D accelaration_;
};

}

#endif // ALICE_PHYSICS_RIGID_BODY_H_